<?php

namespace App\Services;

use App\Models\Activity;
use App\Models\Filter;
use App\Models\Order;

class FilterService extends BaseService
{
    /**
     * 筛选列表
     * @param $filterType
     * @return array|string[]
     */
    public function list($filterType)
    {
        // 设置对象
        $model = Filter::query();
        // 筛选类型
        $model = $model->where('filter_type', $filterType);
        // 获取列表
        $list = $model
            ->orderBy('sort', 'desc')
            ->orderBy('id', 'desc')
            ->get(['id', 'filter_type', 'filter_name'])
            ->toArray();

        if ($filterType == Filter::TYPE_ACTIVITY) {
            $arr = Activity::stateMap();
        } elseif ($filterType == Filter::TYPE_ORDER) {
            $arr = Order::stateMap();
        } else {
            $arr = array_column($list, 'id', 'filter_name') ?? [];
        }

        return $arr;
    }
}
